#pragma once

/*
  nullptr is an upcoming feature in C++11 that allows us to use a TYPE SAFE null pointer that is not NULL or 0.
  Although 0 is a null pointer, it is first and foremost an integral type.  This class resolves that problem
  by converting the integer 0 to the required type.  Another place where this difference is very important is
  in calling functions with overloaded parameters.  Take, for example, the following:

  void func(double* in_ptr)
  {
      std::cout << "Calling func(double*)\n";
  }

  void func(int in_value)
  {
      std::cout << "Calling func(int)\n";
  }

  int main(int argc, char* argv[])
  {
      ...
      func(NULL);
      ...
  }

  This will result in the calling of func(int) even though func(double*) could be more desirable since 0 IS a
  null pointer.  Using the cpac::nullptr as a parameter instead of 0 will result in a call to func(double*)
  thanks to return type resolution.

  It is recommended to nullify a pointer with nullptr to avoid any ambiguities in function calling.

  Note that in the C++11 standard nullptr is a keyword and not a class tucked away in a header file; hence 
  why there is a pre-processing guard over the class declaration.  Use of this nullptr should switch to
  the C++11 keyword automagically without breaking the code that relies on this.
*/

#define GNU_VERSION ((__GNUC__ * 10) + (__GNUC_MINOR__))

#if !defined(__GXX_EXPERIMENTAL_CXX0X__) && (GNU_VERSION < 46) // nullptr supported as of g++4.6

// Implementation taken from page 3 of http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2431.pdf
const class
{
public:
    template< typename _Type >
    inline operator _Type*() const
    {
        return 0;
    }

    template< typename _Class, typename _Type >
    inline operator _Type _Class::*() const
    {
        return 0;
    }

private:
    void operator&() const;
}nullptr = {};

#endif
